
use health/inp_clean if ~no_dx, clear
keep if inrange(admit_date,`=mdy(3,13,2020)',`=mdy(12,22,2020)')		

egen week = cut(admit_date), at(`=mdy(3,13,2020)'(7)`=mdy(12,22,2020)')			
reghdfe test_tight any_icli, absorb(week)
reghdfe test_tight ili, absorb(week)

gen month = month(admit_date)

local months January February March April May June July August September ///
	October November December 
tokenize `months' 

gen c0 = " & " in 1
local c= 0
qui foreach dx in any_icli ili {
	
	forvalues s = 1/3 {		
		
		if `s' == 1 local absorb "noabsorb"
		if `s' == 2 local absorb "absorb(week)"
		if `s' == 3 local absorb "absorb(week inst_id_de)"
		
		local ++c
		local row = 1 
		gen c`c' = "`dx'-`s' &" in `row'
		
		foreach m of numlist 3 4 7 12  {
			local ++row
			replace c0 = "\\" in `row'
			local ++row
			if `m' == 3 {
				local if "if 1"
				replace c0 = "All months \\" in `row'
			}
			if `m' > 3 {
				local if "if month == `m'"
				replace c0 = "``m'' \\" in `row'
			}
			reghdfe test_tight `dx' `if', `absorb' cluster(inst_id_de)
			
			
			local ++row
			replace c0 = "Constant  &" in `row'
			replace c`c' = string(_b[_cons], "%3.2f") + " & " in `row'
			local ++row
			replace c0 = " & " in `row'
			replace c`c' = "(" + string(_se[_cons], "%3.2f") + ") & " in `row'
			
			local ++row
			replace c0 = "Coef. on diagnosis  &" in `row'
			replace c`c' = string(_b[`dx'], "%3.2f") + " & " in `row'
			local ++row
			replace c0 = " & " in `row'
			replace c`c' = "(" + string(_se[`dx'], "%3.2f") + ") & " in `row'
			
			
			
			
			sum `dx' if e(sample)
			local ++row
			replace c0 = "Diagnosis share of admissions &" in `row'
			replace c`c' = string(r(mean), "%3.2f") + " & " in `row'
			
			local ++row
			replace c0 = "\# Observations &" in `row'
			replace c`c' = string(e(N), "%10.0fc") + " & " in `row'
			
			local ++row
			replace c0 = "\# Hospitals &" in `row'
			replace c`c' = string(e(N_clust), "%10.0fc") + " & " in `row'
		}
	}
}

replace c6= subinstr(c6, "&", "\\", .)
noi list c0-c6 in 1/`row', noobs clean
sum test_tight
outsheet c0-c6 in 2/`row' using ///
	tables/test_hosp_monotonicity.tex, replace ///
	noquote nonames delimit(" ")


	
	


** 
